<?
include("common/header.html");
include("common/left.html");
include("common/page.php");
if(empty($_SESSION['alliance'])) exit("<script>window.location='home.html'</script>");

$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$memberID = $_SESSION['memberID'];
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($memberID);

$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$txt=$_REQUEST['txt'];
$dtype=$_REQUEST['dtype'];
$ctype=$_REQUEST['com_type'];
$prov=$_REQUEST['d_province']?$_REQUEST['d_province']:0;
$city=$_REQUEST['d_city']?$_REQUEST['d_city']:0;
$mb=$tpl=$b=$a=$a_sort=array();
if(!$dtype){
	$sel="select dtype from pft_member where id=".$_SESSION['sid']." limit 1";
	$GLOBALS['le']->query($sel);
	$GLOBALS['le']->fetch_assoc();
	$dtype=$GLOBALS['le']->f("dtype");
}
if($_SESSION['group']){
	$sel="select son_id from pft_member_relationship where status=0 and ship_type=1 and parent_id=".$_SESSION['group'];
	$GLOBALS['le']->query($sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$mb[]=$row['son_id'];
	}
}
if($txt && $txt!="请输入企业名称\分销账号\手机"){
	$tj=" and (instr(dname,'".$txt."') or instr(cname,'".$txt."') or account='".$txt."' or mobile='".$txt."')";
}
if($prov || $city || $ctype){
	$a_t=" left join pft_member_extinfo e on e.fid=m.id ";
	$a_tj.=$prov?" and province=".$prov:"";
	$a_tj.=$city?" and city=".$city:"";
	if($ctype){
		$a_tj.=" and (";
		foreach($ctype as $v){
			$a_tj.="instr(com_type,'".$v."') or ";
		}
		$a_tj=trim($a_tj,"or ").")";
	}
}
if($dtype==1){
	$ltitle="供应商列表";
	$sel1="select dname,cname,account,mobile,m.id,ship_type ";
	$sel2="select count(*) total ";
	$sel="from pft_member_relationship r left join pft_member m on m.id=parent_id ".$a_t." where m.status in (0,3) ".$tj.$a_tj." and r.status=0 and son_id=".$_SESSION['sid']." and ship_type=0";
}
elseif($dtype==7){
	$_dtype=isset($_REQUEST['_dtype'])?$_REQUEST['_dtype']:"0,3";
	$ltitle="集团成员列表";
	$sel1="select dname,cname,account,mobile,m.id,ship_type,son_id_type ";
	$sel2="select count(*) total ";
	$sel="from pft_member_relationship r left join pft_member m on m.id=son_id ".$a_t." where m.status in (0,3) ".$tj.$a_tj." and r.status=0 and parent_id=".$_SESSION['sid']." and son_id_type in (".$_dtype.") and ship_type=1";
}
else{

	$ltitle="分销商管理";
	$sel="select id,title from uu_fx_pri_tpl where distid=".$_SESSION['sid'];
	$GLOBALS['le']->query($sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$tpl[]=$row;
	}
	$sel1="select dname,cname,account,mobile,m.id,son_id_type,ship_type ";
	$sel2="select count(*) total ";
	$sel="from pft_member_relationship r left join pft_member m on m.id=son_id ".$a_t." where m.status in (0,3) ".$tj.$a_tj." and r.status=0 and parent_id=".$_SESSION['sid']." and ship_type=0";
}
$GLOBALS['le']->query($sel1.$sel." limit ".($currentPage-1)*$pageSize.",".$pageSize);
while($row=$GLOBALS['le']->fetch_assoc()){
	switch($row['son_id_type']){
		case 0:$row['s_type']="分销商";break;
		case 1:$row['s_type']="资源方";break;
	}
	if($dtype==1){$row['s_type']="供应商";}
	switch($row['ship_type']){
		case 0:$row['type']="供销关系";break;
		case 1:$row['type']="从属关系";break;
		case 2:$row['type']="平级关系";break;
		case 3:$row['type']="推荐关系";break;
	}
	$a_sort[$row['id']]=$row;
}
$GLOBALS['le']->query($sel2.$sel);
$GLOBALS['le']->fetch_assoc();
$total=$GLOBALS['le']->f("total");
$parid=array_keys($a_sort);
if($dtype==0){
	if($parid){
		$sel="select fxid,tplid from uu_fx_tpl_cs where fxid in (".implode(",",$parid).")";
		$GLOBALS['le']->query($sel);
		while($row=$GLOBALS['le']->fetch_assoc()){
			$_tpl[$row['fxid']]=$row['tplid'];
		}
		$_a=simplexml_load_string($s->PFT_Member_Fund(implode(",",$parid),1,$_SESSION['sid']));
		foreach($_a as $v){
			$a[(int)$v->UUfid]=$v->UUkmoney/100;
		}
		$_b=simplexml_load_string($s->PFT_Member_Fund(implode(",",$parid),2,$_SESSION['sid']));
		foreach($_b as $v){
			$b[(int)$v->UUfid]=$v->UUbasecredit/100;
		}
	}
}
elseif($dtype==7){
	$parid=array();
	$GLOBALS['le']->query("select son_id ".$sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		$parid[]=$row['son_id'];
	}
	if($parid){
		$_a=simplexml_load_string($s->PFT_Member_Fund(implode(",",$parid),0));
		foreach($_a as $v){
			$count+=$a[(int)$v->UUfid]=$v->UUamoney/100;
		}
	}
}
else{
	foreach($parid as $v){
		$_a=simplexml_load_string($s->PFT_Member_Fund($_SESSION['sid'],1,$v));
		$a[$v]=$_a->Rec[0]->UUkmoney/100;
		$_b=simplexml_load_string($s->PFT_Member_Fund($_SESSION['sid'],2,$v));
		$b[$v]=$_b->Rec[0]->UUbasecredit/100;
	}
}
$txt=$txt?$txt:"请输入企业名称\分销账号\手机";
include("tpl/alliance_info.tpl");
include("common/footer.html");?>